/*******************************************************************************
**
** Copyright (c) 2011 - The OWE Team
**
** This file is part of OWE.
**
** OWE is a free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License as published by the Free Software Foundation; version
** version 2.1 of the License.
**
** OWE is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public
** License along with OWE. If not, see <http://www.gnu.org/licenses/>.
**
*******************************************************************************/

#include <tut/tut.hpp>
#include <tut/tut_console_reporter.hpp>

#include <owe/element.h>
#include <owe/paramelement.h>
#include <owe/ustring.h>

#include "utests.h"

OWE_USE_NAMESPACE

namespace tut
{
    test_runner_singleton runner;

    struct ParamElement_data {};

    typedef test_group<ParamElement_data> testgroup;
    testgroup shared_ptr_group("ParamElement");
    typedef testgroup::object testobject;

    template<>
    template<>
    void testobject::test<1>() {
        set_test_name("UString ParamElement::name() const");

        ParamElement *element;

        FakeNode param1("param");
        element = static_cast<ParamElement *>(Element::fromNode(&param1));
        ensure(element->name() == "");
        ensure(element->isValid() == false);
        delete element;

        FakeNode param2("param");
        param2.addAttribute("name", "test");
        element = static_cast<ParamElement *>(Element::fromNode(&param2));
        ensure(element->name() == "test");
        ensure(element->isValid() == false);
        delete element;
    }

    template<>
    template<>
    void testobject::test<2>() {
        set_test_name("UString ParamElement::value() const");

        ParamElement *element;

        FakeNode param1("param");
        element = static_cast<ParamElement *>(Element::fromNode(&param1));
        ensure(element->value() == "");
        ensure(element->isValid() == false);
        delete element;

        FakeNode param2("param");
        param2.addAttribute("value", "123");
        element = static_cast<ParamElement *>(Element::fromNode(&param2));
        ensure(element->value() == "123");
        ensure(element->isValid() == false);
        delete element;

        FakeNode param3("param");
        param3.addAttribute("name", "test");
        param3.addAttribute("value", "123");
        element = static_cast<ParamElement *>(Element::fromNode(&param3));
        ensure(element->name() == "test");
        ensure(element->value() == "123");
        ensure(element->isValid() == true);
        delete element;
    }
}

int main(void)
{
    tut::console_reporter reporter;
    tut::runner.get().set_callback(&reporter);
    tut::runner.get().run_tests();

    return reporter.all_ok() ? 0 : 1;
}
